package com.xinghen.ace.auth.util;

import com.xinghen.ace.auth.common.jwt.IJWTInfo;
import com.xinghen.ace.auth.common.jwt.JWTHelper;
import com.xinghen.ace.auth.configuration.KeyConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author xinghen
 * @ClassName: JwtTokenUtil
 * @Package: com.xinghen.ace.auth.util
 * @Description jwt token工具
 * @create 2018/5/4 15:49
 */
@Component
public class JwtTokenUtil {

    @Value("${jwt.expire}")
    private int expire;

    @Autowired
    private KeyConfiguration keyConfiguration;

    public String generateToken(IJWTInfo jwtInfo) throws Exception {
        return JWTHelper.generateToken(jwtInfo, keyConfiguration.getUserPriKey(), expire);
    }

    public IJWTInfo getInfoFromToken(String token) throws Exception {
        return JWTHelper.getInfoFromToken(token, keyConfiguration.getUserPubKey());
    }

}
